<template>
  <div ref="qrCodeDiv" style="width:100%;margin: 0 auto" />
</template>

<script>
import QRCode from 'qrcodejs2'
import { getCompanyId, getQrCodeBaseUrl } from '@/util/storage'
export default {
  name: 'DeviceQrcode',
  props: {
    deviceCore: {
      type: String,
      default: null
    },
    width: {
      type: Number,
      default: 80
    },
    height: {
      type: Number,
      default: 80
    }
  },
  data() {
    return {
      wxCoreUrl: null,
      companyId: getCompanyId()
    }
  },
  created() {
    this.show()
  },
  methods: {
    show() {
      this.$nextTick(() => {
        new QRCode(this.$refs.qrCodeDiv, {
          text: getQrCodeBaseUrl() + '?deviceCore=' + this.deviceCore,
          width: this.width,
          height: this.height,
          colorDark: '#333333', // 二维码颜色
          colorLight: '#ffffff', // 二维码背景色
          correctLevel: QRCode.CorrectLevel.L// 容错率，L/M/H
        })
      })
    }
  }
}
</script>

